<template>
  <div>

    <PreviewDialog :calculatorSore="calculatorSore" :describeContent="describeContent"
                   :fields="items"
                   :medicalCalculatorData="medicalCalculatorData"
                   :type="type"
                   ref="preview"/>

    <el-container style="background-color:white">
      <el-header>
        <div>
          <div style="display: inline-block">
            <el-button @click="goBack" icon="el-icon-back" size="small" type="text">返回</el-button>
          </div>
          <div style="display: inline-block">|</div>
          <div style="display: inline-block;">
            <div style="padding-bottom: 15px;margin-left:10px">
              <span style=" font-family: 'Microsoft YaHei',serif;display: inline-block">医学公式</span>
            </div>
          </div>
          <div style="border-bottom: solid 1px #C9C9C9;"></div>
        </div>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <div id="menu">
            <MenuItem v-for="item in items" :key="item.name" :item="item" @change-selection="refreshList"></MenuItem>
          </div>
        </el-aside>
        <el-main>
          <div id="main-content" :style="{height: mainHeight + 'px'}" style="overflow: auto;">
            <div :item="item" :key="item.name" v-for="item in items">
              <el-row v-if="item.kind === 0">
                <a :name="item.name"></a><!--公式名称  -->
                <el-col :span="24">
                  <div>
                    <span>{{ item.name }}<span style="color: red;">*</span></span>
                  </div>
                  <div class="row">
                    <KindEditor :content.sync="item.property" editor-type="Input" placeholder="请输入公式名称"
                                v-if="isReleased || nameEnable==='1' && (status === CONST.TASK_ITEM.STATUS_NOT_COMMIT || status === CONST.TASK_ITEM.STATUS_REJECT)"
                                width="100%"/>
                    <div v-else>
                      <span v-if='UTIL.hasUnconfirmedNameSuggestion(nameSuggestion)' v-html="item.property" style="color: red;"/>
                      <span v-else v-html="item.property"/>
                      <el-link type="primary" @click.prevent="nameSuggestionDialogVisible = true">修改</el-link>
                      <NameSuggestionDialog
                        :crtName="item.property"
                        :visible.sync="nameSuggestionDialogVisible"
                        :auditLevel="auditLevel"
                        :status="status"
                        :nameSuggestion="nameSuggestion"
                        @confirm="updateNameSuggestion"
                        @cancel="nameSuggestionDialogVisible = false"/>
                    </div>
                  </div>
                </el-col>
              </el-row>
              <el-row v-if="item.kind === 1">
                <a :name="item.name"></a><!-- 又称 -->
                <div>
                  <span>{{ item.name }}</span>
                </div>
                <div class="row">
                  <div style="margin-bottom: 10px;">
                    <MultiValueBox ref="component" :fieldValue.sync="item.property"/>
                  </div>
                </div>
              </el-row>

              <el-row v-if="item.kind === 3">
                <a :name="item.name"></a><!-- 学科分类 -->
                <div>
                  <span>{{ item.name }}</span>
                </div>
                <div class="row">
                  <el-cascader v-model="item.property" :options="item.tagId" :props="cascadeProps"
                               style="width: 100%"></el-cascader>
                </div>
              </el-row>
              <el-row v-if="item.kind === 2">
                <a :name="item.name"></a><!-- 关联平台 -->
                <div>
                  <span>{{ item.name }}<span style="color: red;">*</span></span>
                </div>
                <div class="row">
                  <el-select multiple placeholder="请选择" style="width: 100%" v-model="item.property">
                    <el-option
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                      v-for="item in platforms">
                    </el-option>
                  </el-select>
                </div>
              </el-row>
              <el-row v-if="item.kind === 4">
                <a :name="item.name"></a><!-- 公式说明 -->
                <div>
                  <span>{{ item.name }}</span>
                </div>
                <div class="row">
                  <KindEditor :content.sync="item.property" editor-type="Input" placeholder="请输入公式说明"
                              width="100%"/>
                </div>
              </el-row>
            </div>
            <el-row>
              <a name="公式类型"></a>
              <el-col :span="24">
                <div>
                  <span>公式类型：</span>
                </div>
                <div class="row">
                  <el-radio-group @change="valueChange()" v-model="type">
                    <el-radio :label="1">计算型</el-radio>
                    <el-radio :label="2">评分型</el-radio>
                    <el-radio :label="3">描述型</el-radio>
                  </el-radio-group>
                </div>
              </el-col>
            </el-row>
            <el-row> <!-- 公式描述 -->
              <a id="公式描述"></a>
              <el-col :span="24">
                <div v-if="type === 1">
                  <div :idx="index"
                       :key="acl.id"
                       :value="acl"
                       @input="change"
                       style="margin-bottom: 10px;margin-left:10px;display: inline-block;width: 45%"
                       v-for="(acl, index) in medicalCalculatorData">
                    <div style="padding:1px; border:1px solid; margin:0 0 0 0px">
                      <div :style="{height: calculateHeight + 'px'}" style="overflow-y: scroll">
                        <el-button plain type="success" v-on:click="add(index)">复制此大项</el-button>
                        <el-button :style="{ display:calculatorEnable}" plain type="danger" v-on:click="del(index)">
                          删除此大项
                        </el-button>
                        <div>分支选项说明<span :style="{ display:spanEnable }"><em style="color: red">*</em></span></div>
                        <div>
                          <el-input v-if="inputEnable" placeholder="默认分支选项说明" disabled v-model="acl.explain"></el-input>
                          <KindEditor :content.sync="acl.explain" editor-type="Input" placeholder="请输入分支选项说明" v-else
                                      width="100%"/>
                        </div>
                        <FormulaType :prop="acl.calculateData"/>
                        <el-row>
                          <el-col :span="3">
                            <div class="row-label" style="padding: 0 5px;">
                              <span>计算结果解析</span>
                            </div>
                          </el-col>
                          <el-col :span="21">
                            <div STYLE="margin: 10px 0px;" style="padding: 0 5px;">
                              <AnalysisGroup @input="change" v-model="acl.sections"></AnalysisGroup>
                            </div>
                          </el-col>
                        </el-row>
                      </div>
                    </div>
                  </div>
                </div>
                <div v-else-if="type === 2">
                  <div :idx="index"
                       :key="calSore.id"
                       :value="calSore"
                       @input="change"
                       style="margin-bottom: 10px;margin-left:10px;display: inline-block;width: 45%"
                       v-for="(calSore, index) in calculatorSore">
                    <div style="padding:1px; border:1px solid; margin:0 0 0 0px;">
                      <div :style="{height: scoreHeight + 'px'}" style="overflow-y: scroll;">
                        <el-button plain type="success" v-on:click="addSore(index)">复制此大项</el-button>
                        <el-button :style="{ display:scoreEnable }" plain type="danger" v-on:click="delSore(index)">
                          删除此大项
                        </el-button>
                        <div>分支选项说明<span :style="{ display:spanEnable }"><em style="color: red">*</em></span></div>
                        <div>
                          <el-input disabled placeholder="默认分支选项说明" v-if="inputEnable"
                                    v-model="calSore.explain"></el-input>
                          <KindEditor :content.sync="calSore.explain" editor-type="Input" placeholder="请输入分支选项说明" v-else
                                      width="100%"/>
                        </div>
                        <div style="margin-top: 10px">
                          <ScoreSection @input="change" v-model="calSore.scoreData"></ScoreSection>
                          <el-row>
                            <el-col :span="3">
                              <div class="row-label" style="padding: 0 5px;">
                                <span>计算结果解析</span>
                              </div>
                            </el-col>
                            <el-col :span="21">
                              <div STYLE="margin: 10px 0px;" style="padding: 0 5px;">
                                <AnalysisGroup @input="change" v-model="calSore.sections"></AnalysisGroup>
                              </div>
                            </el-col>
                          </el-row>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <div>
                  <div>
                    <el-row>
                      <el-col :span="3" style="padding: 0 5px;">
                        <div class="label">评价方法<span style="color: red">*</span></div>
                      </el-col>
                      <el-col :span="24" style="padding: 0 5px;">
                        <div style="margin: 10px 0px;">
                          <KindEditor :content.sync="describeContent"
                                      :uploadPath="'calculator/' + editId"/>
                        </div>
                      </el-col>
                    </el-row>
                  </div>
                </div>
                <div v-if="type != 3" id="analysis">

                </div>
              </el-col>
            </el-row>
            <div :item="item" :key="item.id" v-for="item in items">
              <el-row v-if="item.kind ===6"> <!-- 结果说明 -->
                <a :name="item.name"></a>
                <el-col :span="24">
                  <div>
                    <span>{{ item.name }}</span>
                  </div>
                  <div style="padding: 2px;">
                    <KindEditor :content.sync="item.property"
                                :uploadPath="'calculator/' + editId"/>
                  </div>
                </el-col>
              </el-row>
              <el-row v-if="item.kind === 7"> <!-- 参考文献 -->
                <a :name="item.name"></a>
                <el-col :span="24">
                  <div>
                    <span>{{ item.name }}</span>
                  </div>
                  <div>
                    <KindEditor :content.sync="item.property" editor-type="Textarea"/>
                  </div>
                </el-col>
              </el-row>
              <ToTopButton @to-top="toTop"></ToTopButton>
            </div>
          </div>
        </el-main>
      </el-container>
      <el-footer style="height: 30px; ">
        <div style="border-top: solid 1px #C9C9C9; position: relative">
          <div style="float: right">
            <el-button size="small" @click="cancelEdit">取 消</el-button>
            <el-button @click="previewDialogVisible = true" size="small">预览</el-button>
            <el-button @click="save()" size="small" type="success">保存</el-button>
            <el-button :style="{ display:commitEnable }" @click="commit()" size="small" type="success">提交</el-button>
            <el-button :style="{ display:rejectEnable }" plain size="small" type="danger" @click="rebut()">驳回
            </el-button>
            <el-button :style="{ display:auditEnable }" @click="pass()" size="small" type="success">审核通过</el-button>
          </div>
        </div>
      </el-footer>
    </el-container>
    <el-dialog
      :visible.sync="rejectVisible"
      title="提示"
      width="30%">
      <el-input type="textarea" v-model="reject"></el-input>
      <span class="dialog-footer" slot="footer">
    <el-button @click="rejectVisible = false">取 消</el-button>
    <el-button @click="saveReject" type="primary">确 定</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>
import MenuItem from "../common/MenuItem";
import AnalysisGroup from "./ResultAnalysis/AnalysisGroup";
import ScoreSection from "./ScoreSection/ScoreSection";
import ToTopButton from "../edit/ToTopButton";
import FormulaType from "./FormulaType";
import KindEditor from "../kindeditor/KindEditor";
import PreviewDialog from "./exportModel/PreviewDialog";
import NameSuggestionDialog from "../knowledge/knowledgeEdit/NameSuggestionDialog";
import MultiValueBox from "../knowledge/knowledgeEdit/MultiValueBox"

export default {
  beforeRouteLeave(to, from, next) {
    //跳转到搜索页面时，search为搜索页面名称
    to.meta.isUseCache = true;
    next();
  },
  name: "FormulaEditor",
  components: {
    NameSuggestionDialog,
    PreviewDialog,
    KindEditor,
    FormulaType,
    ToTopButton,
    ScoreSection,
    MenuItem,
    AnalysisGroup,
    MultiValueBox
  },
  data() {
    return {
      previewDialogVisible: false,

      cascadeProps: {         // 集联控件属性
        multiple: true,
        checkStrictly: true,
      },
      resultDescription: '',  // 结果说明
      calculateData: {},
      medicalCalculatorData: [],
      calculatorSore: [],
      describeContent: '',    // 描述型描述
      items: [],              // 左侧导航栏数据
      sections: [],           // 计算结果解析数据
      scoreData: [],          // 评分数据
      formulaName: "",        // 公式名称
      subject: [],            // 学科分类
      subjectOptions: [],     // 学科分类选项
      type: 1,                // 公式类型
      reference: "",          // 参考文献
      mainHeight: 0,          // 内容区域的高度
      postData: {},           // 提交的数据
      response: {             // 应答数据结构
        result: "",           // 提交结果
        message: "",          // 应答信息
        data: {}
      },
      platforms: [],
      platform: [],
      editId: '',
      explain: '',
      inputEnable: true,
      calculateHeight: '',
      scoreHeight: '',
      saveEnable: '',
      commitEnable: '',
      rejectEnable: 'none',
      auditEnable: 'none',
      rejectReason: '',
      rejectVisible: false,
      calculatorEnable: '',
      scoreEnable: '',
      waitingResponse: false,
      addEnable: '',
      releasedEnable: '',
      nameEnable: '',
      isReleased: false,
      nameSuggestion: {},
      nameSuggestionDialogVisible: false,
      auditLevel: 0,
      status: 0,
      spanEnable: 'none'
    }
  }
  ,
  methods: {
    updateNameSuggestion(nameSuggestion) {
      this.nameSuggestion = nameSuggestion
      this.nameSuggestionDialogVisible = false
    }
    ,
    refreshList(item) {
      window.location.href = '#' + item.name;
      this.setAllItemsUnselected();
      this.setSelectedItem(item);
    },
    valueChange() {
      if (this.type === 1) {
        this.type === '1'
      } else {
      }
    }
    ,
    setAllItemsUnselected() {
      this.items.forEach(item => {
        item.selected = false;
      });
    }
    ,
    cal: function () {

      console.log(this.medicalCalculatorData)
    }
    ,
    goBack: function () {
      this.$router.back()
    }
    ,
    add: function (index) {
      this.medicalCalculatorData.push({
        calculateData: {},
        sections: []
      })
      if (this.medicalCalculatorData.length > 1) {
        this.inputEnable = false
        this.calculatorEnable = ''
        this.spanEnable = ''
      } else {
        this.calculatorEnable = 'none'
        this.spanEnable = 'none'
      }
    }
    ,
    change1: function () {

    }
    ,
    change() {

    }
    ,
    saveReject: function () {
      if (!this.reject) {
        this.$message.warning("请填写驳回原因");
        return
      }
      this.rejectVisible = false
      this.$confirm('确定驳回当前医学公式？', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let param = new URLSearchParams();
        param.append("id", this.editId)
        param.append("reject", this.reject)
        this.axios.post('/pmph/action/medicalCalculator/rejectCalculator', param)
          .then((response) => {
            this.$router.push("/myAudit")
          });
      })
    }
    ,
    del(index) {
      this.$confirm('是否删除？', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if (this.medicalCalculatorData.length > 1) {
          this.medicalCalculatorData.splice(index, 1)
        }
        if (this.medicalCalculatorData.length <= 1) {
          this.explain = ''
          this.inputEnable = true
          this.calculatorEnable = 'none'
          this.spanEnable = 'none'
        }
      })

    }
    ,
    addSore() {
      this.calculatorSore.push({
        scoreData: [],
        sections: []
      })
      if (this.calculatorSore.length > 1) {
        this.inputEnable = false
        this.scoreEnable = ''
        this.spanEnable = ''
      } else {
        this.scoreEnable = 'none'
        this.spanEnable = 'none'
      }
    }
    ,
    delSore(index) {
      this.$confirm('是否删除？', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if (this.calculatorSore.length > 1) {
          this.calculatorSore.splice(index, 1)
        }
        if (this.calculatorSore.length <= 1) {
          this.explain = ''
          this.inputEnable = true
          this.scoreEnable = 'none'
          this.spanEnable = 'none'
        }
      })
    }
    ,
    setSelectedItem(selectedItem) {
      this.items.forEach(item => {
        if (item.name === selectedItem.name) {
          item.selected = true;
        }
      });
    }
    ,
    /**
     * 这个函数主要用于展示传入各个组件的数据结构是什么样的
     */
    getFormulaData() {
      this.items = [{
        name: "公式名称",
        selected: true,
        require: true,
        kind: 0,
        property: ''
      }, {
        name: "又称",
        selected: false,
        require: false,
        kind: 1,
        property: []
      }, {
        name: "学科分类",
        selected: false,
        require: false,
        kind: 2,
        property: []
      }, {
        name: "关联平台",
        selected: false,
        require: false,
        kind: 3,
        property: []
      }, {
        name: "公式说明",
        selected: false,
        require: false,
        kind: 4,
        property: ''
      }, {
        name: "公式类型",
        selected: false,
        require: false,
        kind: 10,

      }, {
        name: "结果说明",
        selected: false,
        require: false,
        kind: 7,
        property: ''
      }, {
        name: "参考文献",
        selected: false,
        require: false,
        kind: 6,
        property: ''
      }]

      this.sections = [{
        id: 0, // 解析顺序
        sections: [{ // 解析条件
          id: 0, // 条件顺序
          condition: 0, // 大于，小于等
          relation: 0, // 或，且
          value: 0 // 数值
        }],
        explanation: "", // 解析结果说明
        result: "default", // button
        isLegalInterval: true // 区间计算结果是否合法。空集即为不合法
      }]

      this.scoreData = [{
        id: 0,
        name: "question1",
        multiple: false,
        items: [{
          id: 0,
          score: 10,
          describe: "hello"
        }, {
          id: 1,
          score: 20,
          describe: "world"
        }]
      }, {
        id: 1,
        name: "question 2",
        multiple: true,
        items: [{
          id: 0,
          score: 30,
          describe: "apple"
        }, {
          id: 1,
          score: 40,
          describe: "big"
        }]
      }]

      this.calculateData = {
        formulaItems: [
          {
            item_id: 'a',
            item_name: '脉压',
            item_unit: 'mmHG',
          },
          {
            item_id: 'b',
            item_name: '脉率',
            item_unit: 'mmHG',
          },
          {
            item_id: 'c',
            item_name: '哇哈哈',
            item_unit: 'mmHG',
          }
        ],
        // 公式;
        formulaExpressionItems: [
          {
            item_expression: '( b + 0.74 * a ) * 0.75 - 72',
            item_type: '身高小于165cm',
          },
          {
            item_expression: '( b + 0.74 * a ) * 0.72 - 75',
            item_type: '身高大于165cm',
          },
        ],
        formulaDescription: '基础代谢率=(脉率+脉压差*0.74)*0.75-72',
        resultUnit: 'm',
      }
    }
    ,
    cancelEdit() {
      this.$router.go(-1)
    }
    ,
    rebut() {
      this.$prompt('请输入驳回原因', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: /.+/,
        inputErrorMessage: '驳回原因不能为空'
      }).then(({value}) => {
        this.reject(value)
      })
    }
    ,
    save() {
      if (this.waitingResponse) {
        return
      }
      let noProblem = this.checkRequiredFields()
      if (noProblem) {
        this.waitingResponse = true
        this.assemblePostData()
        let param = new URLSearchParams();
        param.append("data", JSON.stringify(this.postData))
        param.append("isReleased", this.isReleased)
        param.append("taskItemId", this.$route.query.taskItemId)
        param.append("nameSuggestion", JSON.stringify(this.nameSuggestion))
        this.axios
          .post("/pmph/action/medicalCalculator/save", param)
          .then(response => {
            this.$router.back()
            this.waitingResponse = false
          })
      }
    }
    ,
    commit() {
      if (this.waitingResponse) {
        return
      }
      let noProblem = this.checkRequiredFields()
      if (noProblem) {
        this.waitingResponse = true
        this.assemblePostData()
        let param = new URLSearchParams();
        param.append("data", JSON.stringify(this.postData))
        param.append("taskItemId", this.$route.query.taskItemId)
        param.append("nameSuggestion", JSON.stringify(this.nameSuggestion))
        this.axios
          .post("/pmph/action/medicalCalculator/commit", param)
          .then(response => {
            this.$router.back()
            this.waitingResponse = false
          })
      }
    }
    ,
    pass() {
      if (this.waitingResponse) {
        return
      }
      let noProblem = this.checkRequiredFields()
      if (noProblem) {
        this.$confirm('此操作会把知识传递给下一个审核人或完成审核流程，从而无法再编辑此知识，您确定要这样做吗？',
          '请确认操作', {
            confirmButtonText: '确定',
            cancelButtonText: '取消'
          }).then(() => {
          this.waitingResponse = true
          this.assemblePostData()
          let param = new URLSearchParams();
          param.append("data", JSON.stringify(this.postData))
          param.append("nameSuggestion", JSON.stringify(this.nameSuggestion))
          this.axios
            .post("/pmph/action/medicalCalculator/pass", param)
            .then(response => {
              this.$router.back()
              this.waitingResponse = false
            })
        })
      }
    }
    ,
    reject(rejectReason) {
      if (this.waitingResponse) {
        return
      }
      let noProblem = this.checkRequiredFields()
      if (noProblem) {
        this.waitingResponse = true
        this.assemblePostData()
        let param = new URLSearchParams();
        param.append("data", JSON.stringify(this.postData))
        param.append("rejectReason", rejectReason)
        param.append("nameSuggestion", JSON.stringify(this.nameSuggestion))
        this.axios
          .post("/pmph/action/medicalCalculator/reject", param)
          .then(response => {
            this.$router.back()
            this.waitingResponse = false
          })
      }
    }
    ,
    assemblePostData() {
      if (this.editId) {
        this.postData.id = this.editId
      }
      this.postData.type = this.type
      this.postData.items = this.items
      this.postData.calculateData = this.calculateData
      this.postData.scoreData = this.scoreData
      this.postData.describeContent = this.describeContent
      this.postData.sections = this.sections
      this.postData.medicalCalculatorData = this.medicalCalculatorData
      this.postData.calculatorSore = this.calculatorSore
    }
    ,
    checkRequiredFields() {
      if (!this.items[0].property) {
        this.$message.warning("必须填写公式名称")
        return false
      }
      for (let i = 0; i < this.items.length; i++) {
        if (this.items[i].kind === 2) {
          if (this.items[i].property.length <= 0) {
            this.$message.warning("必须填写关联平台")
            return false
          }
        }
      }
      for (let i = 0; i < this.calculatorSore.length; i++) {
        if (this.calculatorSore.length > 1 && !this.calculatorSore[i].explain) {
          this.$message.warning("请填写分支说明")
          return false
        }
      }
      for (let i = 0; i < this.medicalCalculatorData.length; i++) {
        if (this.medicalCalculatorData.length > 1 && !this.medicalCalculatorData[i].explain) {
          this.$message.warning("请填写分支说明")
          return false
        }
      }
      if (this.type === 1) {
        for (let i = 0; i < this.medicalCalculatorData.length; i++) {
          for (let j = 0; j < this.medicalCalculatorData[i].calculateData.formulaExpressionItems.length; j++) {
            if (!this.medicalCalculatorData[i].calculateData.formulaExpressionItems[j].item_expression) {
              this.$message.warning("必须填写公式")
              return false
            }
          }
        }
      } else if (this.type === 2) {
        for (let i = 0; i < this.calculatorSore.length; i++) {
          if (!this.calculatorSore[i].scoreData || this.calculatorSore[i].scoreData.length === 0) {
            this.$message.warning("必须填写评分题")
            return false
          }
        }
      }
      if (!this.describeContent) {
        this.$message.warning("必须填写评价方法")
        return false
      }
      // 检查计算结果解析的区间计算结果是否都合法
      for (let i = 0; i < this.sections.length; i++) {
        if (this.sections[i].isLegalInterval === false) {
          this.$message.warning("计算结果解析区间不合理")
          return false
        }
      }
      return true
    }
    ,
    toTop() {
      document.getElementById('main-content').scrollTop = 0
    }
  }
  ,
  created() {

    this.nameEnable = this.$route.query.enableCreate
    this.valueChange()
    if (this.$route.query.auditStatus === 'audit') {
      this.addEnable = ''
      this.saveEnable = 'none'
      this.commitEnable = 'none'
      this.rejectEnable = ''
      this.auditEnable = ''
      this.releasedEnable = 'none'
    } else if (this.$route.query.auditStatus === 'released') {
      this.addEnable = 'none'
      this.saveEnable = 'none'
      this.commitEnable = 'none'
      this.rejectEnable = 'none'
      this.auditEnable = 'none'
      this.releasedEnable = ''
      this.isReleased = true
    } else {
      this.addEnable = 'none'
      this.saveEnable = ''
      this.commitEnable = ''
      this.rejectEnable = 'none'
      this.auditEnable = 'none'
      this.releasedEnable = 'none'
    }
    this.calculateHeight = CONST.WORKSPACE_HEIGHT - 210;
    this.scoreHeight = CONST.WORKSPACE_HEIGHT - 350;
    this.medicalCalculatorData.push({
      calculateData: {},
      sections: []
    })
    this.calculatorSore.push({
      scoreData: [],
      sections: []
    })
    if (this.medicalCalculatorData.length === 1) {
      this.calculatorEnable = 'none'
    } else {
      this.calculatorEnable = ''
    }
    if (this.calculatorSore.length === 1) {
      this.scoreEnable = 'none'
    } else {
      this.scoreEnable = ''
    }
    this.editId = this.$route.query.id

    this.axios.get("/pmph/action/medicalCalculator/selectPlatform", {})
      .then((response) => {
        this.platforms = response.data
      })
      .catch((error) => {
        this.$message.error("获取名称失败")
      })
    if (this.editId) {

    } else {
      this.axios.get("/pmph/action/medicalCalculator/selectCalculatorField", {})
        .then((response) => {
          this.items = response.data.fields;
          this.editId = response.data.id;
          if (this.$route.query.enableCreate === '1') {
            this.items[0].property = this.$route.query.itemName
            this.items[0].selected = true;
          } else {
            this.items[0].property = this.$route.query.itemName
            this.items[0].selected = true;
          }
          for (let i = 0; i < this.items.length; i++) {
            if (this.items[i].kind === 1) {
              this.items[1].property = []
            }
          }
        })
        .catch((error) => {
          this.$message.error("获取字段失败")
        })
    }
    // 计算内容区域的高度
    this.mainHeight = CONST.WORKSPACE_HEIGHT - 130
  }
  ,
  mounted() {
    let url = ''
    this.editId = this.$route.query.id
    if (this.$route.query.nameSuggestion) {
      this.nameSuggestion = JSON.parse(this.$route.query.nameSuggestion)
    }
    this.auditLevel = this.$route.query.auditLevel
    this.status = Number(this.$route.query.status)
    if (this.$route.query.auditStatus === 'released') {
      url = "/pmph/action/medicalCalculator/selectReleasedCalculatorById"
    } else {
      url = "/pmph/action/medicalCalculator/selectDataById"
    }
    if (this.$route.query.id) {
      this.axios.get(url, {
        params: {
          id: this.$route.query.id
        }
      })
        .then((res) => {
          this.items = res.data.fields
          this.type = res.data.type
          this.medicalCalculatorData = res.data.medicalCalculatorData
          this.scoreData = res.data.scoreData
          this.describeContent = res.data.describeContent
          this.calculatorSore = res.data.calculatorSore
          if (res.data.calculatorSore.length === 0) {
            this.calculatorSore.push({
              scoreData: [],
              sections: []
            })
          }
          if (res.data.medicalCalculatorData.length === 0) {
            this.medicalCalculatorData.push({
              calculateData: {},
              sections: []
            })
          }
          if (this.medicalCalculatorData.length > 1) {
            this.inputEnable = false
          }
          if (this.calculatorSore.length > 1) {
            this.inputEnable = false
          }
          for (let i = 0; i < res.data.fields.length; i++) {
            if (res.data.fields[i].kind === 2) {
              this.items[i].property = JSON.parse(res.data.fields[i].property)
            }
            if (res.data.fields[i].kind === 1) {
              this.items[i].property = JSON.parse(res.data.fields[i].property)
            }
            if (res.data.fields[i].kind === 3 && res.data.fields[i].ident === 0 && res.data.fields[i].property) {
              this.items[i].property = JSON.parse(res.data.fields[i].property)
            }
            if (res.data.fields[i].kind === 3 && res.data.fields[i].ident === 1) {
              if (!res.data.fields[i].property) {
                this.items[i].property = res.data.fields[i].property
              } else {
                this.items[i].property = res.data.fields[i].property
              }
            }
          }
        })
        .catch((err) => {
          this.$message.error(err)
          console.error(err)
        })
    }
  }
}
</script>

<style scoped>
/* 子组件textarea, 指定字体 */
/deep/ textarea {
  font-family: 'Microsoft YaHei', serif
}

/* 不显示div的滚动条 */
::-webkit-scrollbar {
  display: none
}

.row {
  margin-bottom: 20px;
}

.row-label {
  text-align: right;
  margin-right: 10px;
  margin-top: 8px;
}

.inline-block {
  display: inline-block;
}

.el-main {
  padding: 5px 20px 20px;
}

.label {
  float: left;
}
</style>
